package leetcode.t1Array;

import java.util.HashMap;
import java.util.Map;

/**
 * @author K
 * @date 2024/1/23 13:32
 */
public class T1_TwoSum {
    /**
     * 1题 两数之和
     * HashMap
     */
    public static int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int num = nums[i];
            int other = target - num;
            if (!map.containsKey(other)) {
                map.put(num, i);
            } else {
                return new int[]{i, map.get(other)};
            }
        }
        return new int[]{};
    }

    public static void main(String[] args) {
        int[] nums = {2, 7, 11, 15};
        int[] ints = twoSum(nums, 9);
        int[] ints2 = twoSum(new int[]{3, 2, 4}, 6);
        int[] ints3 = twoSum(new int[]{3, 3}, 6);
        System.out.println();
    }

}
